﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Configuration;
using TheCollectiveNetwork.Classes.GlobalFunctions;
using TheCollectiveNetwork.Classes.Globals;

using TheCollectiveNetwork.Classes.Debugging;

namespace TheCollectiveNetwork.Classes.UserManagement
{
   
        public class usermanagement_SQL
        {
            
            /* Private Variables */
           

            /* Constructors */
            public usermanagement_SQL()
            {
                
            }

            #region Properties
            /* Properties */

           
                              
                                  
            #endregion

            #region Public Functions
            /*Public Functions*/

            // Validates the username and password in the database
            public DataTable FindUserName(string pSearchString)
            {
                string FilteredSearchString;
                FilteredSearchString = Regex.Replace(strfunc.Left(pSearchString, 255), "[^0-9a-z'\"~@_\\-\\.]", string.Empty, RegexOptions.IgnoreCase);

                string rsql;
                SqlCommand sqlcmd; 
                SqlConnection dbconn;
                SqlDataAdapter sqldata;
                DataTable dt;

	            dbconn = new SqlConnection(ConfigurationManager.AppSettings[constring.write_str]);

                rsql = " Select username from Accounts_User where username like @searchtxt order by username; ";
                sqlcmd = new SqlCommand(rsql, dbconn);
                sqlcmd.Parameters.AddWithValue("@searchtxt", "%" + FilteredSearchString + "%");

                dt = new DataTable();
                sqldata = new SqlDataAdapter();
                sqldata.SelectCommand = sqlcmd;
	            sqldata.Fill(dt);
                sqldata = null;
	            dbconn.Close();

                return dt;
                
            }
                
            

            
            #endregion

       
            #region Private Functions
            /*Private Functions*/

         

            #endregion




        }
                
           

}
